package com.shadeien.concurrent.thread;

import lombok.extern.slf4j.Slf4j;

@Slf4j
public class InheritableThreadLocalExample {
//    static ThreadLocal<String> threadLocal = new ThreadLocal<>();
    static ThreadLocal<String> threadLocal = new InheritableThreadLocal<>();

    public static void main(String[] args) {
        new Thread(() -> {
            threadLocal.set(threadLocal.toString());
            new Service().call();
        }).start();
    }
}

class Service {
    public void call() {
        System.out.println(Thread.currentThread().getName() + " : " + InheritableThreadLocalExample.threadLocal.get());
        new Thread(() -> {
            new Service2().call();
        }).start();
    }
}

class Service2 {

    public void call() {
        System.out.println(Thread.currentThread().getName() + " : " + InheritableThreadLocalExample.threadLocal.get());
    }
}
